/*
 * application_common.h
 *
 *  Created on: Jul 17, 2013
 *      Author: m
 */

#ifndef APPLICATION_COMMON_H_
#define APPLICATION_COMMON_H_

#include <string>
#include <cstring>
#include <iostream>
#include "application_exception.h"

#define SERIALIZED_STR_MAXLENGTH 256

// TODO: eliminar estos donde se pueda...
#define BUS_STATION_REQUEST_BASENAME "busStationRequest."
#define BUS_STATION_PASSENGER_BASENAME "busStationPassenger."
#define PASSENGER_NOTIFICATION_BASENAME "passengerNotification."
#define UNLOAD_REPLY_QUEUE_BASENAME "unloadReply."
#define LOAD_REPLY_QUEUE_BASENAME "loadReply."

struct FixedSizeString
{
    char m_data[SERIALIZED_STR_MAXLENGTH];

    FixedSizeString()
    {
        m_data[0] = '\0';
    }

    FixedSizeString( const FixedSizeString &rhs )
    {
        *this = rhs;
    }

    FixedSizeString( std::string data )
    {
        if ( data.size() >= SERIALIZED_STR_MAXLENGTH )
        {
            throw Exception( "String is too long to serialize: '" + data + "'" );
        }

        strncpy( m_data, data.c_str(), SERIALIZED_STR_MAXLENGTH );
    }

    FixedSizeString& operator=( const FixedSizeString &rhs )
    {
        if ( this == &rhs )
        {
            return *this;
        }

        strncpy( m_data, rhs.m_data, SERIALIZED_STR_MAXLENGTH );

        return *this;
    }

    FixedSizeString& operator=( const std::string &data )
    {
        if ( data.size() >= SERIALIZED_STR_MAXLENGTH )
        {
            throw Exception( "String is too long to serialize: '" + data + "'" );
        }

        strncpy( m_data, data.c_str(), SERIALIZED_STR_MAXLENGTH );

        return *this;
    }

};

// TODO: Me servirá esto?
typedef std::string queueName_t;
typedef FixedSizeString serializedQueueName_t;

namespace application
{

typedef enum { ENTRANCE_DOOR, EXIT_DOOR } doorType;
typedef enum { ENTRANCE_BUS_STATION, EXIT_BUS_STATION } busStationType;
typedef enum { ENTRANCE_BUS, EXIT_BUS } busType;

typedef std::string doorId;
typedef std::string visitorId;
typedef std::string busStationId;
typedef std::string busId;

} /* namespace business */
#endif /* APPLICATION_COMMON_H_ */
